# -*- coding: utf-8 -*-
"""
created on 2017/12/8 13:36

@author: didichen
"""

# 开始url：http://www.pythonchallenge.com/pc/return/italy.html
# 结束url：http://www.pythonchallenge.com/pc/return/cat.html-->http://www.pythonchallenge.com/pc/return/uzi.html

import requests
from PIL import Image

img = Image.open('wire.png')
img_data = list(img.getdata())

img_new = Image.new(img.mode, size=(100, 100))
img_new_data = img_new.load()

MAX_LENGTH = 100
index = 0
x = 0
y = 0
len_list = [[i, i - 1, i - 1, i - 2] for i in range(100, 1, -2)]
for start_index in range(0, len(len_list)):
    [len_right, len_down, len_left, len_up] = len_list[start_index]
    for i in range(0, len_right):
        # print(start_index, start_index + i)
        img_new_data[(start_index, start_index + i)] = img_data[index]
        index += 1
    for i in range(0, len_down):
        # print(start_index + 1 + i, MAX_LENGTH - start_index-1)
        img_new_data[(start_index + 1 + i, MAX_LENGTH - start_index-1)] = img_data[index]
        index += 1
    for i in range(1,len_left+1):
        # print(MAX_LENGTH - start_index-1, MAX_LENGTH - start_index-1-i)
        img_new_data[(MAX_LENGTH - start_index-1, MAX_LENGTH - start_index-1-i)] = img_data[index]
        index += 1
    for i in range(1,len_up+1):
        # print(MAX_LENGTH - start_index -1- i, start_index)
        img_new_data[(MAX_LENGTH - start_index -1- i, start_index)] = img_data[index]
        index += 1

img_new.show()
